package com.yzh.dxpro.p5.TopN;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.Job;

public class DxTopNMain {

	public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
		Configuration conf = new Configuration();
		//设置map和reduce内存使用大小
		conf.set("mapreduce.map.memory.mb", "3072");
		conf.set("mapreduce.reduce.memory.mb", "2048");
		//参数传递
		//排序字段：用户ID
		conf.set("topkey", "1");
		//排序值：PV访问量
		conf.set("topvalue", "2");
		//排序取前N条记录：前五条
		conf.set("topn", "5");
		Job job =Job.getInstance(conf, "Dx_TopN");
		job.setJarByClass(DxTopNMain.class);
		job.setMapperClass(DxTopNMapper.class);
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(Text.class);
		job.setReducerClass(DxTopNReducer.class);
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(Text.class);
		//输入路径
		FileInputFormat.addInputPath(job, new Path(args[0]));
		//输出路径
		FileOutputFormat.setOutputPath(job, new Path(args[1]));
		//提交作业 判断退出条件（0正常退出，1非正常退出）
		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}
}
